package gunfire.actions;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.GainEnergyAction;
import com.megacrit.cardcrawl.actions.common.MakeTempCardInHandAction;
import com.megacrit.cardcrawl.actions.defect.DiscardPileToHandAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.ui.panels.EnergyPanel;
import com.megacrit.cardcrawl.vfx.combat.FlashAtkImgEffect;
import gunfire.cards.CrimsonFirescale2;
import gunfire.cards.DoubleCaliber;

public class DoubleCaliberAction extends AbstractGameAction {
    private DamageInfo info;
    private static final float DURATION = 0.1F;
    private boolean upgraded;

    public DoubleCaliberAction(AbstractCreature target, DamageInfo info, boolean upgraded) {
        this.info = info;
        this.setValues(target, info);
        this.actionType = ActionType.DAMAGE;
        this.duration = 0.1F;
        this.upgraded = upgraded;
    }

    public void update() {
        if (this.duration == 0.1F && this.target != null) {
            AbstractDungeon.effectList.add(new FlashAtkImgEffect(this.target.hb.cX, this.target.hb.cY, AttackEffect.SLASH_HORIZONTAL));
            this.target.damage(this.info);
//            if ((this.target.isDying || this.target.currentHealth <= 0) && !this.target.halfDead) {
            if ((this.target.isDying || this.target.currentHealth <= 0)) {
                this.addToBot(new GainEnergyAction(2));
                AbstractCard c = new DoubleCaliber();
                if(this.upgraded){
                    c.upgrade();
                }
                this.addToBot(new MakeTempCardInHandAction(c, 1, false));
            }

            if (AbstractDungeon.getCurrRoom().monsters.areMonstersBasicallyDead()) {
                AbstractDungeon.actionManager.clearPostCombatActions();
            }
        }

        this.tickDuration();
    }
}
